/*===============================================*/
/*================= RESTAT MS24757 ==============*/
/*============== F.Cumming & P.Hubert ===========*/
/*============== Time series analysis ===========*/
/*===============================================*/

drop _all
clear matrix
global DIR "C:\XXX"
cd "${DIR}"

use "RESTAT_MS24757_Macro_data.dta", clear 
tsset date

//---- Merge with Regional data
merge 1:1 date using "Reg_Statevar.dta"
drop if _merge==2
drop _merge
rename *lti* *li*

//----- Axis variables
gen zero = 0
gen xaxis = 0 if _n==1
replace xaxis = xaxis[_n-1]+1 if _n>1
replace xaxis = . if _n>19

//--- Labels
label variable cpi "Consumer price inflation"
label variable ndur_c_m "Non-durable cons."
label variable dur_c_m "Durable cons."
label variable ser_c_m "Services"
label variable tot_c_m "Total consumption"
label variable indpro "Industrial production"
label variable emp_yoy "Employment"
label variable unemp "Unemployment" 
label variable sterling "Sterling exch. rate"
label variable ftse "FTSE prices"
label variable clendn "Net consumer lending"
label variable gdp_m "Real GDP growth"
label variable li_95 "Raw-LTI>p(95)"
label variable li_adj_75 "LTI>p(75)"
label variable li_adj_90 "LTI>p(90)"
label variable li_adj_95 "LTI>p(95)"
label variable li_adj_975 "LTI>p(97.5)"
label variable li_adj_poor "LTI>p(95) & Income<p(75)"
label variable li_adj_lv75 "LTI>p(95) & LTV>75"
label variable li_adj_old "LTI>p(95) & Age>p(50)"
label variable li_adj_exl "LTI>p(95) & Excl. L&SE"
label variable li_fit_95 "CF-trend-corr LTI>p(95)"
label variable li_adj_levn "LTI>p(95) & Level-NoPCincome"
label variable li_adj_logy "LTI>p(95) & Log-PCincome"
label variable li_adj_logn "LTI>p(95) & Log-NoPCincome"
label variable lv_adj_95 "LTV>p(95)" 
label variable pti_adj_95 "PTI>p(95)"
label variable li_adj_ex_lv "LTV"
label variable li_adj_ex_pti "PTI"

* share of variable rate
gen mst_fl_sh = mst_fl / mst_all * 100 

/*====================================================*/
/*=========== Identifying Monetary Shocks  ===========*/
/*====================================================*/

cap drop *_shock

//----- Monetary shocks
reg D.r_2y L.r_2y ///
cbm_cpi_4 cbm_cpi_8 cbm_cpi_12 D.cbm_cpi_4 D.cbm_cpi_8 D.cbm_cpi_12 ///
cbm_gdp_4 cbm_gdp_8 cbm_gdp_12 D.cbm_gdp_4 D.cbm_gdp_8 D.cbm_gdp_12 ///
L(0/3).unemp ir_month L.sef_cpi_2y L.swap_2y
predict r_2y_shock, residuals
label variable r_2y_shock
//
reg D.r_2y L.r_2y ///
cbm_cpi_4 cbm_cpi_8 cbm_cpi_12 D.cbm_cpi_4 D.cbm_cpi_8 D.cbm_cpi_12 ///
cbm_gdp_4 cbm_gdp_8 cbm_gdp_12 D.cbm_gdp_4 D.cbm_gdp_8 D.cbm_gdp_12 ///
L(0/3).unemp ir_month L.sef_cpi_2y L.swap_2y 
estat dwatson
lincom "D.cbm_cpi_4 + D.cbm_cpi_8 + D.cbm_cpi_12"
lincom "D.cbm_gdp_4 + D.cbm_gdp_8 + D.cbm_gdp_12"
//
reg r_2y_shock L(1/3).r_2y_shock
lincom "L1.r_2y_shock + L2.r_2y_shock + L3.r_2y_shock"

//---- Shadow rate (Krippner) shock
reg D.krip L.krip ///
cbm_cpi_4 cbm_cpi_8 cbm_cpi_12 D.cbm_cpi_4 D.cbm_cpi_8 D.cbm_cpi_12 ///
cbm_gdp_4 cbm_gdp_8 cbm_gdp_12 D.cbm_gdp_4 D.cbm_gdp_8 D.cbm_gdp_12 ///
L(0/3).unemp ir_month L.sef_cpi_2y L.swap_2y
eststo
predict krip_shock, residuals
label variable krip_shock

//---- Bank rate shock
local variable boe_r
foreach var of local variable {
reg D.`var' L.`var' ///
cbm_cpi_4 cbm_cpi_8 cbm_cpi_12 D.cbm_cpi_4 D.cbm_cpi_8 D.cbm_cpi_12 ///
cbm_gdp_4 cbm_gdp_8 cbm_gdp_12 D.cbm_gdp_4 D.cbm_gdp_8 D.cbm_gdp_12 ///
L(0/3).unemp ir_month L.sef_cpi_2y L.swap_2y if date<tm(2009m4)
predict `var'_shock if date<tm(2009m4), residuals
label variable `var'_shock
}

//--- Sum MP shock
cap drop *_shsum
local variable r_2y krip boe_r
foreach var of local variable {
gen `var'_shsum = 0
replace `var'_shsum = `var'_shock + L.`var'_shsum if `var'_shock!=.
replace `var'_shsum = . if `var'_shock==.
}


//--- Validity of monetary shocks
local variable r_2y krip  
foreach var of local variable {
reg `var'_shock L(1/6).cpi L(1/6).indpro L(1/6).oil L(1/6).sterling L(1/6).netlending L(1/6).hp 
}

/*======================================================================*/
/*============= Loan-level Exogenous State-variables ===================*/
/*======================================================================*/

//----- Smoothing 
cap drop s_*
local variable li_adj_75 li_adj_90 li_adj_95 li_adj_975 ///
li_adj_ex_lv li_adj_ex_pti ///
li_adj_poor li_adj_lv75 li_adj_old li_adj_exl ///
li_adj_mean li_adj_med lv_adj pti_adj ///
li_adj_levn li_adj_logy li_adj_logn
foreach var of local variable {
tssmooth ma s_`var' = `var', window(2 1 2) replace
label variable s_`var'
}

//----- Trend/cycle decomposition of fitted values: minperiod(18)=1.5y / maxperiod(96)=8y
cap drop c*_li_fit_*
local variable li_fit_95
foreach var of local variable {
tsfilter cf c6_`var' = `var', minperiod(6) 
label variable c6_`var'
tsfilter cf c18_`var' = `var', minperiod(18)   
label variable c18_`var'
}

//--- State-variable plot
cap drop li_adj_95_100 
cap drop c6_li_fit_95_100
gen li_adj_95_100 = li_adj_95*100
gen c6_li_fit_95_100 = c6_li_fit_95*100
//
cap drop li_p95_*_100
forvalues i = 1(1)12 {
gen li_p95_`i'_100 = li_p95_`i'*100
}

/*=====================================================*/
/*===================== Figure 1 ======================*/
/*=====================================================*/

twoway (line c6_li_fit_95_100 date, lcolor(black) lwidth(medthick) yaxis(2)) ///
(line li_p95_1_100 date, lcolor(gs11) lwidth(thin)) (line li_p95_2_100 date, lcolor(gs11) lwidth(thin)) ///
(line li_p95_3_100 date, lcolor(gs11) lwidth(thin)) (line li_p95_4_100 date, lcolor(gs11) lwidth(thin)) ///
(line li_p95_5_100 date, lcolor(gs11) lwidth(thin)) (line li_p95_6_100 date, lcolor(gs11) lwidth(thin)) ///
(line li_p95_7_100 date, lcolor(gs11) lwidth(thin)) (line li_p95_8_100 date, lcolor(gs11) lwidth(thin)) ///
(line li_p95_9_100 date, lcolor(gs11) lwidth(thin)) (line li_p95_10_100 date, lcolor(gs11) lwidth(thin)) ///
(line li_p95_11_100 date, lcolor(gs11) lwidth(thin)) (line li_p95_12_100 date, lcolor(gs11) lwidth(thin)) ///
(connected li_adj_95_100 date, lcolor(black) lwidth(medthick) mcolor(black) msymbol(circle) msize(medium) mfco(none)) ///
if li_adj_95_100!=., yscale(alt) yscale(alt axis(2)) ///
xsize(4) ysize(2) scale(1.3) aspectratio(0.33) xtitle("") ///
xtitle("") xlabel(540(24)691, format(%tmCCYY) labsize(medsmall)) ///
ylabel(0(4)12, angle(horiz) axis(1)) ytitle("Percent", axis(1)) ///
ylabel(-4(4)4, angle(horiz) axis(2)) ytitle("Percent deviations", axis(2)) ///
graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) plotregion(fcolor(white) lcolor(white) ///
ifcolor(white) ilcolor(white)) plotregion(lcolor(black)) legend(cols(3) size(medium) symysize(*.4) symxsize(*.3) rowgap(*.03) ///
ring(0) position(2) order(14 "S{subscript:t}" 2 "S{subscript:t,r}" 1 "S{subscript:t}{superscript:d}"))
graph export Fig1.png, width(3000) height(1500) replace
graph export Fig1.eps, replace

/*======================================================================*/
/*============================== Figure 2 ==============================*/
/*======================================================================*/

//------ Fig2a ------// 
cap drop h_*r2y* 
cap drop l_*r2y*
local cyclevar s
local statevar li_adj_95
local variable tot_c_m                           
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/3).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "`mpshock' + ($m)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_r2y_`var'_)
quietly mat list alpha16
quietly mat drop _all
}
}
} 
local cyclevar s
local statevar li_adj_95
local variable tot_c_m   
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(black) lwidth(thin)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_1 h_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_2 h_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(4 "Average effect") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
//
set graphics on
graph combine `cyvar'_`stvar'_`var', ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export Fig2a.png, width(1000) height(1000) replace
graph export Fig2a.eps, replace
}
}
}

//------ Fig2b ------// 
cap drop h_*r2y* 
cap drop l_*r2y*
local cyclevar s
local statevar li_adj_95
local variable tot_c_m                       
local forward F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
foreach lead of local forward {
quiet sum `cyvar'_`stvar'
global m  = r(mean)
global sd = r(sd)
local mpshock r_2y_shsum
local controls L1.`var' L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.`var' L(0/3).(c.`cyvar'_`stvar'##c.`mpshock') c.`cyvar'_`stvar'##c.(`controls'), vce(rob)
global high "`mpshock' + ($m+$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
global low "`mpshock' + ($m-$sd)*c.`cyvar'_`stvar'#c.`mpshock'"
quiet lincom $high
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha11=nullmat(alpha11), p_a2_`lead'_`var'_`stvar'
matrix alpha12=nullmat(alpha12), p_a1_`lead'_`var'_`stvar'
matrix alpha13=nullmat(alpha13), p_bet_`lead'_`var'_`stvar'
matrix alpha14=nullmat(alpha14), p_b1_`lead'_`var'_`stvar'
matrix alpha15=nullmat(alpha15), p_b2_`lead'_`var'_`stvar'
matrix alpha16=alpha11\alpha12\alpha13\alpha14\alpha15
scalar drop _all
quiet lincom $low
scalar p_bet_`lead'_`var'_`stvar' = r(estimate)
scalar p_se_`lead'_`var'_`stvar' = r(se)
scalar p_a1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1*p_se_`lead'_`var'_`stvar'
scalar p_b1_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1*p_se_`lead'_`var'_`stvar'
scalar p_a2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' + 1.64*p_se_`lead'_`var'_`stvar'
scalar p_b2_`lead'_`var'_`stvar' = p_bet_`lead'_`var'_`stvar' - 1.64*p_se_`lead'_`var'_`stvar'
matrix alpha21=nullmat(alpha21), p_a2_`lead'_`var'_`stvar'
matrix alpha22=nullmat(alpha22), p_a1_`lead'_`var'_`stvar'
matrix alpha23=nullmat(alpha23), p_bet_`lead'_`var'_`stvar'
matrix alpha24=nullmat(alpha24), p_b1_`lead'_`var'_`stvar'
matrix alpha25=nullmat(alpha25), p_b2_`lead'_`var'_`stvar'
matrix alpha26=alpha21\alpha22\alpha23\alpha24\alpha25
scalar drop _all
}
quietly matrix alpha16=alpha16'
quietly matrix alpha26=alpha26'
quietly svmat alpha16, names(h_`cyvar'_`stvar'_r2y_`var'_)
quietly svmat alpha26, names(l_`cyvar'_`stvar'_r2y_`var'_)
quietly mat list alpha16
quietly mat list alpha26
quietly mat drop _all
}
}
} 
local cyclevar s
local statevar li_adj_95
local variable tot_c_m
foreach cyvar of local cyclevar {
foreach stvar of local statevar {
foreach var of local variable {
local vtext : variable label `var' 
if `"`vtext'"' == "" local vtext "`v'" 
local v2text : variable label `stvar' 
if `"`v2text'"' == "" local vtext "`v'"
set graphics off
twoway (line zero xaxis, lcolor(black) lwidth(thin)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_1 l_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(75) lcolor(navy) lwidth(none)) ///
(rarea l_`cyvar'_`stvar'_r2y_`var'_2 l_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(100) lcolor(navy) lwidth(none)) ///
(connected l_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(black)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_1 h_`cyvar'_`stvar'_r2y_`var'_5 xaxis, fcolor(gray) fintensity(25) lcolor(gray) lwidth(none)) ///
(rarea h_`cyvar'_`stvar'_r2y_`var'_2 h_`cyvar'_`stvar'_r2y_`var'_4 xaxis, fcolor(gray) fintensity(50) lcolor(gray) lwidth(none)) ///
(connected h_`cyvar'_`stvar'_r2y_`var'_3 xaxis, lcolor(black) mcolor(black) msymbol(circle) msize(large) mfcolor(none)) if _n<14, ///
ylabel(-4(2)2, angle(horizontal) labsize(medium) axis(1)) ytitle("Per cent", axis(1)) xtitle("") ///
xlabel(0(3)12, labsize(medium)) graphregion(fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(fcolor(white) lcolor(black) ifcolor(white) ilcolor(white)) name(`cyvar'_`stvar'_`var', replace) ///
title(`"`vtext'"', size(medlarge) color(black)) legend(cols(1) order(7 "High S{subscript:t}" 4 "Low S{subscript:t}") ///
size(medsmall) symysize(*.4) symxsize(*.4) rowgap(*.1) colgap(*.1) ring(0) position(11)) aspectratio(0.9) 
}
set graphics on  // grc1leg
graph combine `cyvar'_`stvar'_tot_c_m, ///
rows(1) cols(1) ycommon imargin(tiny) graphregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) ///
plotregion(margin(tiny) fcolor(white) lcolor(white) ifcolor(white) ilcolor(white)) iscale(*1.1) xsize(1) ysize(1) 
graph export Fig2b.png, width(1000) height(1000) replace
graph export Fig2b.eps, replace
}
}

/*===========================================================*/
/*========================= Table 2 =========================*/
/*===========================================================*/

//
cap drop m_s_li_adj_95 c_li_adj_95
eststo clear
egen m_s_li_adj_95 = mean(s_li_adj_95)
gen c_li_adj_95 = s_li_adj_95 - m_s_li_adj_95
replace c_li_adj_95 = c_li_adj_95*100
//
local forward F1 F3 F6 F9 F12
foreach lead of local forward {
quiet sum c_li_adj_95
global m  = r(mean)
global sd = r(sd)
//
local controls L1.tot_c_m L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
eststo `lead' : quiet reg `lead'.tot_c_m L(0/3).(c.c_li_adj_95##c.r_2y_shsum) c.c_li_adj_95##c.(`controls'), vce(rob)
//
global high "r_2y_shsum + ($m+$sd)*c.c_li_adj_95#c.r_2y_shsum"
global mean "r_2y_shsum + ($m)*c.c_li_adj_95#c.r_2y_shsum"
global low "r_2y_shsum + ($m-$sd)*c.c_li_adj_95#c.r_2y_shsum"
quiet lincom $high
scalar h_bet_`lead' = r(estimate)
scalar h_se_`lead' = r(se)
quiet lincom $mean
scalar m_bet_`lead' = r(estimate)
scalar m_se_`lead' = r(se)
quiet lincom $low
scalar l_bet_`lead' = r(estimate)
scalar l_se_`lead' = r(se)
//
estadd scalar h_bet_`lead' : `lead'
estadd scalar h_se_`lead' : `lead'
estadd scalar m_bet_`lead' : `lead'
estadd scalar m_se_`lead' : `lead'
estadd scalar l_bet_`lead' : `lead'
estadd scalar l_se_`lead' : `lead'
//
local controls L1.tot_c_m L(0/1).emp_yoy L(0/1).mfw_all L(0/1).clendn ///
L(0/1).mfw_sh_fl L(0/1).D.mst_fl_sh L(0/1).remortg L(0/1).hp L(0/1).r L(0/1).mort_dur L(0/1).iqr_li_ym 
quiet reg `lead'.tot_c_m L(0/3).(c.c_li_adj_95##c.r_2y_shsum) c.c_li_adj_95##c.(`controls'), vce(rob)
	scalar r2_`lead' = e(r2)
quiet reg `lead'.tot_c_m L(1/3).(c.c_li_adj_95##c.r_2y_shsum) c.c_li_adj_95##c.(`controls'), vce(rob)
	scalar r2w_`lead' = e(r2)
	scalar pr2_`lead' = (r2_`lead' - r2w_`lead')/(1 - r2w_`lead')
estadd scalar r2_`lead' : `lead'
estadd scalar pr2_`lead' : `lead'
}
esttab F* using Tab2.rtf, b(3) se(2) br noeqlines nogaps nolines star(* 0.1 ** 0.05 *** 0.01) ///
keep(c_li_adj_95 r_2y_shsum c.c_li_adj_95#c.r_2y_shsum) depvars order() ///
stats(N r2_F1 r2_F3 r2_F6 r2_F9 r2_F12 pr2_F1 pr2_F3 pr2_F6 pr2_F9 pr2_F12 ///
h_bet_F1 h_bet_F3 h_bet_F6 h_bet_F9 h_bet_F12 h_se_F1 h_se_F3 h_se_F6 h_se_F9 h_se_F12 ///
m_bet_F1 m_bet_F3 m_bet_F6 m_bet_F9 m_bet_F12 m_se_F1 m_se_F3 m_se_F6 m_se_F9 m_se_F12 ///
l_bet_F1 l_bet_F3 l_bet_F6 l_bet_F9 l_bet_F12 l_se_F1 l_se_F3 l_se_F6 l_se_F9 l_se_F12) replace
scalar drop _all 
eststo clear


/*=====================================================*/
/*========== Collapse for regional estimates  =========*/
/*=====================================================*/

collapse (mean) r_2y_shsum, by(yearq)
gen dateq = tq(2004q4) + _n-1
format %tq dateq
tsset dateq
save "RESTAT_MS24757_Agg_Macro_data.dta", replace


